#pragma once
#include <memory>

#include "Protocol.hpp"
#include "Service.hpp"

/// @brief 只负责计算，不负责下层的序列化和反序列化
class NetCal
{
public:
    NetCal()
    {
    }

    std::shared_ptr<Response> Calculator(std::shared_ptr<Request> req)
    {
        auto resp = Factory::BuildResponseDefault();
        switch (req->GetOper())
        {
        case '+':
        {
            resp->SetResult(req->GetX() + req->GetY());
            break;
        }
        case '-':
        {
            resp->SetResult(req->GetX() - req->GetY());
            break;
        }
        case '*':
        {
            resp->SetResult(req->GetX() * req->GetY());
            break;
        }
        case '/':
        {
            if (req->GetY() == 0)
            {
                resp->SetCode(1);
                resp->SetDesc("Div Zero!");
            }
            else
            {
                resp->SetResult(req->GetX() / req->GetY());
            }
            break;
        }
        case '%':
        {
            if (req->GetY() == 0)
            {
                resp->SetCode(1);
                resp->SetDesc("Mod Zero!");
            }
            else
            {
                resp->SetResult(req->GetX() % req->GetY());
            }
            break;
        }
        default:
        {
            resp->SetCode(2);
            resp->SetDesc("Unknown operation!");
        }
        }
        return resp;
    }

    ~NetCal()
    {
    }

private:
};